package com.li.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.util.DisplayMetrics;
import android.view.WindowManager;

/**
 * Created by Li on 2017/3/2.
 * get info about screen
 */

public class ScreenUtil {

    /**
     * getScreenSize
     * @param context   context
     * @return  point.x:screenWidth;point.y:screenHeight
     */
    public static Point getScreenSize(Context context){
        DisplayMetrics displayMetrics=context.getApplicationContext().getResources().getDisplayMetrics();
        return new Point(displayMetrics.widthPixels,displayMetrics.heightPixels);
    }

    public static int getScreenWidth(Context context){
        return getScreenSize(context).x;
    }
    public static int getScreenHeight(Context context){
        return getScreenSize(context).y;
    }

    public static void setWindowAlpha(Activity activity,float alpha){
        WindowManager.LayoutParams params=activity.getWindow().getAttributes();
        params.alpha=alpha;
        activity.getWindow().setAttributes(params);

    }

    /**
     * getStatusBarHeight
     * @param context
     * return statusBarHeight
     */
    public static int getStatusBarHeight(Context context) {
        //获取status_bar_height资源的ID
        int resourceId = context
                .getApplicationContext()
                .getResources()
                .getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            //根据资源ID获取响应的尺寸值
            return context.getApplicationContext().getResources().getDimensionPixelSize(resourceId);
        }
        return 0;
    }
}
